package com.wjh.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjh.yygh.common.result.Result;
import com.wjh.yygh.model.user.UserInfo;
import com.wjh.yygh.user.service.UserInfoService;
import com.wjh.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户列表")
    @GetMapping("/{page}/{limit}")
    public Result<IPage<UserInfo>> list(@PathVariable("page") Long page
            , @PathVariable("limit") Long limit
            , UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> userInfoPage = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(userInfoPage, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "用户锁定")
    @GetMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        boolean lock = userInfoService.lock(id, status);
        if (lock) {
            return Result.ok().code(200).message("修改成功");
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "用户详情页")
    @GetMapping("/show/{id}")
    public Result<Map<String, Object>> show(@PathVariable("id") Long id) {
        Map<String, Object> map = userInfoService.show(id);
        return Result.ok(map);
    }

    @GetMapping("/approval/{id}/{authStatus}")
    public Result approval(@PathVariable("id") Long id, @PathVariable("authStatus") Integer authStatus){

        userInfoService.approval(id,authStatus);
        return Result.ok();

    }



}
